//----------------------------------------------------------------------------
//  ,-.
// /_\___ ,   Ninja Framework
// '  ___\    (C) Riccardo Capra - http://riccar.do
//  //   \\
//----------------------------------------------------------------------------
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------------

#include "NjNinjaSync.h"
#include "NjGenericStaticInterface.h"
#include "NjAssert.h"

//----------------------------------------------------------------------------
void NjGenericStaticInterface::Implementation::OnSetImplementation()
{
	NJ_ASSERT(!m_bIsImplementationSet);
	m_bIsImplementationSet=NJ_TRUE;
}
//----------------------------------------------------------------------------
void NjGenericStaticInterface::Implementation::OnUnsetImplementation()
{
	NJ_ASSERT(m_bIsImplementationSet);
	m_bIsImplementationSet=NJ_FALSE;
}
//----------------------------------------------------------------------------
void NjGenericStaticInterface::OnUnsetImplementation(OnImplementationCallBack * pHead, Implementation * pImplementation)
{
	while (pHead!=NJ_NULL)
	{
		pHead->OnUnsetImplementation(pImplementation);
		pHead=pHead->m_pNext;
	}

	pImplementation->OnUnsetImplementation();
}
//----------------------------------------------------------------------------
void NjGenericStaticInterface::OnSetImplementation(OnImplementationCallBack * pHead, Implementation * pImplementation)
{
	pImplementation->OnSetImplementation();

	while (pHead!=NJ_NULL)
	{
		pHead->OnSetImplementation(pImplementation);
		pHead=pHead->m_pNext;
	}
}
//----------------------------------------------------------------------------
void NjGenericStaticInterface::AddImplementationCallBack(OnImplementationCallBack * * ppHead, OnImplementationCallBack * pEntry)
{
	pEntry->m_pNext=(*ppHead);
	(*ppHead)=pEntry;
}
//----------------------------------------------------------------------------
void NjGenericStaticInterface::RemoveImplementationCallBack(OnImplementationCallBack * * ppHead, OnImplementationCallBack * pEntry)
{
	for(;;)
	{
		OnImplementationCallBack * const pCurrent(*ppHead);

		if (pCurrent==NJ_NULL)
		{
			NJ_BREAK();
			return;
		}

		if (pCurrent==pEntry)
		{
			(*ppHead)=pCurrent->m_pNext;
			return;
		}

		ppHead=&pCurrent->m_pNext;
	}
}
//----------------------------------------------------------------------------
